<template>
  <div>
    <!-- 置顶栏S -->
   <div class="RoomMesgTop" >
    <form action="/" >
  <van-search
    v-model="CityId.name"
    show-action
    placeholder="请输入搜索关键词"
    :input-align="center"
    @focus="center = 'left'"
    @blur="CityId.name.length === 0 ? center = 'center' : center = 'left'"
    @input="oninput"
    @cancel="$router.back()"
  />
</form>
      </div>
   <!-- 置顶栏E -->
   <div>
    <van-cell v-for="(item,index) in area" :key="index" @click="AreaBtn(item)">
      {{item.communityName}}
    </van-cell>
   </div>
  </div>
</template>

<script>
import { CellKeywordsRequest } from '@/api'
export default {
  data () {
    return {
      // 渲染房屋列表
      area: [],
      // 搜索框文字居中
      center: 'center',
      // 请求发生携带的参数
      CityId: {
        name: '',
        id: 'AREA|19b39d4f-8a36-d6f8'
      }
    }
  },
  methods: {
    async oninput () {
      if (this.CityId.name === '') {
        this.area = []
        return
      }
      try {
        const res = await CellKeywordsRequest(this.CityId)
        this.area = res.data.body
      } catch (err) {
        console.log(err)
      }
    },
    AreaBtn (item) {
      this.$router.replace({
        name: 'add',
        params: {
          item
        }
      })
    }
  }
}
</script>

<style lang="less">
</style>
